package com.zjm.principle.lod;

import java.util.List;

/**
 * 迪米特法则
 */
public class Demeter02 {
    public static void main(String[] args) {
        Company1 company = new Company1();
        company.printAllEmployeeNames(); // 只依赖 Company 接口
    }
}

class Company1 {
    private List<Department1> departments;

    public void printAllEmployeeNames() {
        for (Department1 department : departments) {
            department.printEmployeeNames();
        }
    }
}

class Department1 {
    private List<Employee1> employees;

    public void printEmployeeNames() {
        for (Employee1 employee : employees) {
            System.out.println(employee.getName());
        }
    }
}

class Employee1 {
    private String name;

    public String getName() {
        return name;
    }
}
